'use strict';
module.exports = (app) => {
  // 商品分类表
  const { STRING, INTEGER, ENUM, JSON } = app.Sequelize;
  const Classify = app.model.define('s_classify', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    user_id: {
      type: INTEGER,
      comment: '用户id',
    },
    project_id: {
      type: INTEGER,
      comment: '项目id',
    },
    name: {
      type: STRING,
      comment: '类型名称',
      allowNull: false,
    },
    sort: {
      type: STRING,
      comment: '排序,从小到大',
      defaultValue: 999,
    },
    parent_id: {
      type: INTEGER,
      comment: '父类ID',
      defaultValue: 0,
    },
    status: {
      type: ENUM('0', '1', '2'),
      comment: '状态，0停用,1可用,2删除',
      defaultValue: '1',
    },
    thumb_url: {
      type: STRING,
      comment: '缩略图路径',
    },
    path: {
      type: STRING,
      comment: '分类路径',
      defaultValue: '0',
    },
  });

  Classify.associate = function () {
    // 一对多链接商品表
    app.model.Tables.Shop.Classify.hasMany(app.model.Tables.Shop.Goods, {
      foreignKey: 'classify_id',
    });
  };
  // 同步表结构
  Classify.sync({ alter: true });

  return Classify;
};
